package cn.iocoder.yudao.module.vr.dal.mysql.order;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.vr.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.vr.dal.dataobject.game.GameDO;
import cn.iocoder.yudao.module.vr.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.vr.dal.dataobject.order.OrderDetailDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.vr.controller.admin.order.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * vr订单 Mapper
 *
 * @author Lau
 */
@Mapper
public interface OrderMapper extends BaseMapperX<OrderDO> {

    default PageResult<OrderDetailDO> selectPage(OrderPageReqVO reqVO) {
        return selectJoinPage(reqVO,OrderDetailDO.class,new MPJLambdaWrapperX<OrderDO>()
                .selectAll(OrderDO.class)
                .selectAs(GameDO::getName, OrderDetailDO::getGameName)
                .selectAs(DeviceDO::getName, OrderDetailDO::getDeviceName)
                .betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
                .eqIfExists(OrderDO::getOrderCode, reqVO.getOrderCode())
                .eqIfExists(OrderDO::getGameId, reqVO.getGameId())
                .eqIfExists(OrderDO::getDeviceId, reqVO.getDeviceId())
                .eqIfExists(OrderDO::getPlayTime, reqVO.getPlayTime())
                .eqIfExists(OrderDO::getAmount, reqVO.getAmount())

                .leftJoin(DeviceDO.class,DeviceDO::getId,OrderDO::getDeviceId)
                .leftJoin(GameDO.class,GameDO::getId,OrderDO::getGameId)
        );





    }
    @Select("select sum(amount) as amount,count(1) as count from vr_order where create_time >= #{start} and create_time < #{end}")
    OrderAnalysisTimeRespVO getOrderAnalysis (@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);


}